package com.reader.cms.service.impl.sys;

import com.baomidou.mybatisplus.plugins.Page;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.reader.cms.entity.sys.SysRole;
import com.reader.cms.mapper.sys.SysRoleMapper;
import com.reader.cms.service.sys.ISysRoleService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
/**
 * @@description  服务实现类
 * @author        gumenghao
 * @date          2018-09-25
 */
@Service
@Transactional
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {


@Autowired
private SysRoleMapper sysRoleMapper;

/**
 * @function 多表关联查询
 * @param     currentPage 当前页
 * @param     size 每页显示条数
 * @param     name 其它参数，自行定义
 * @return
 */
    @Transactional(readOnly=true)
    @Override
    public Page<Map<String, Object>> selectListPage(int currentPage,int size,String name) {
            Page<Map<String, Object>> page = new Page<>(currentPage, size);// 当前页，总条数 构造 page 对象
            return page.setRecords(sysRoleMapper.selectListPage(page,name));
    }

    @Override
    public List<SysRole> selectAllRoles() {

        return sysRoleMapper.selectAllRoles();
    }

    @Override
    public List<SysRole> getRolesOfOrganization(String code) {

        return sysRoleMapper.getRolesOfOrganization(code);
    }

    @Override
    public List<Integer> getRolesOfUserId(Integer id) {

        return sysRoleMapper.getRolesOfUserId(id);
    }

    @Override
    public void configPermission(SysRole sysRole) {
        sysRoleMapper.deletePermission(sysRole.getId());
        sysRoleMapper.insertPermission(sysRole.getId(),sysRole.getMenuIds());
    }

    @Override
    public boolean judgeDel(Integer id) {
        boolean flag = true;
        Integer count = sysRoleMapper.judeDel(id);
        if(count > 0){
           flag = false;
        }
        return flag;
    }
}